﻿<UserControl x:Class="Neurotoxin.Godspeed.Shell.Views.ProfileRebuilderPane" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:inf="clr-namespace:Neurotoxin.Godspeed.Presentation.Infrastructure;assembly=Neurotoxin.Godspeed.Presentation"
             xmlns:e="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:vc="clr-namespace:Neurotoxin.Godspeed.Shell.Views.Controls" 
             xmlns:converters="clr-namespace:Neurotoxin.Godspeed.Shell.Converters"
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
             xmlns:selectors="clr-namespace:Neurotoxin.Godspeed.Shell.Views.Selectors"
             xmlns:views="clr-namespace:Neurotoxin.Godspeed.Shell.Views"
             lex:LocalizeDictionary.DesignCulture="en-US"
             lex:ResxLocalizationProvider.DefaultAssembly="Neurotoxin.Godspeed.Shell"
             lex:ResxLocalizationProvider.DefaultDictionary="Resources">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Themes/WhistlerBlue.xaml" />
                <ResourceDictionary>
                    <converters:FileBlockHealthStatusConverter x:Key="FileBlockHealthStatusConverter" />
                    <selectors:ProfileRebuilderContentTemplateSelector x:Key="ProfileRebuilderContentTemplateSelector">
                        <selectors:ProfileRebuilderContentTemplateSelector.FileStructureTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <ListBox ItemsSource="{Binding Content}" x:Name="List">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="100" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>

                                                    <TextBlock Text="{Binding Name}" />
                                                    <ItemsControl Grid.Column="1" ItemsSource="{Binding Blocks}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <VirtualizingStackPanel Orientation="Horizontal" />
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <Border CornerRadius="4" Background="{Binding Health, Converter={StaticResource FileBlockHealthStatusConverter}}"
                                                                        Margin="0,0,5,0" Padding="2" Width="30">
                                                                    <TextBlock Text="{Binding BlockNumber}" TextAlignment="Center" />
                                                                </Border>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Grid>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                        <e:Interaction.Triggers>
                                            <e:EventTrigger EventName="MouseDoubleClick">
                                                <inf:MapMouseEventToCommand Command="{Binding Path=DataContext.OpenTabCommand, ElementName=LayoutRoot}"
                                                                            CommandParameter="{Binding ElementName=List, Path=SelectedItem}"/>
                                            </e:EventTrigger>
                                        </e:Interaction.Triggers>
                                    </ListBox>
                                    <Grid Grid.Row="1" DataContext="{Binding ElementName=List, Path=SelectedItem}" Background="LightGray">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{Binding Name}"/>
                                        <TextBlock Grid.Column="1" Text="{Binding FileSize}"/>
                                        <TextBlock Grid.Column="2" Text="{Binding Date}"/>
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </selectors:ProfileRebuilderContentTemplateSelector.FileStructureTemplate>
                        <selectors:ProfileRebuilderContentTemplateSelector.GpdContentTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <ListBox ItemsSource="{Binding Content}" x:Name="List">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="100" />
                                                    </Grid.ColumnDefinitions>

                                                    <TextBlock Grid.Column="0" Text="{Binding Name}" />
                                                    <TextBlock Grid.Column="1" Text="{Binding EntryType}" />
                                                </Grid>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                    <!--<Grid Grid.Row="1" DataContext="{Binding ElementName=List, Path=SelectedItem}" Background="LightGray">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{Binding Name}"/>
                                        <TextBlock Grid.Column="1" Text="{Binding FileSize}"/>
                                        <TextBlock Grid.Column="2" Text="{Binding Date}"/>
                                    </Grid>-->
                                </Grid>
                            </DataTemplate>
                        </selectors:ProfileRebuilderContentTemplateSelector.GpdContentTemplate>
                    </selectors:ProfileRebuilderContentTemplateSelector>


                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="29" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Margin="0,2,0,5" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="{lex:LocText Close}" Command="{Binding CloseCommand}" MinWidth="60" Padding="10,0,10,0" />
        </StackPanel>

        <Border Grid.Row="1" Background="{Binding Path=IsActive, Converter={StaticResource PaneHeaderBackgroundConverter}}"
             BorderBrush="#FF9B9999" BorderThickness="1,1,1,0" SnapsToDevicePixels="True">
            <TextBlock Text="{lex:LocText ProfileRebuilder}" Padding="2" FontWeight="Bold" />
        </Border>
        
        <TabControl Grid.Row="2" 
                    ItemsSource="{Binding Tabs}" 
                    SelectedItem="{Binding SelectedTab}"
                    ContentTemplateSelector="{StaticResource ProfileRebuilderContentTemplateSelector}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <DockPanel>
                        <Button DockPanel.Dock="Right" Command="{Binding ElementName=LayoutRoot, Path=DataContext.CloseTabCommand}" CommandParameter="{Binding}">
                            <Button.Template>
                                <ControlTemplate TargetType="{x:Type Button}">
                                    <Grid Background="Transparent">
                                        <Path x:Name="ButtonPath"
                                              Margin="10,3,3,3"
                                              Stroke="{StaticResource NormalBrush}"
                                              StrokeThickness="1.5"
                                              StrokeStartLineCap="Square"
                                              StrokeEndLineCap="Square"
                                              Stretch="Uniform"
                                              VerticalAlignment="Center"
                                              HorizontalAlignment="Center"
                                              Width="8"
                                              Height="8">
                                            <Path.Data>
                                                <PathGeometry>
                                                    <PathGeometry.Figures>
                                                        <PathFigure StartPoint="0,0">
                                                            <LineSegment Point="25,25"/>
                                                        </PathFigure>
                                                        <PathFigure StartPoint="0,25">
                                                            <LineSegment Point="25,0"/>
                                                        </PathFigure>
                                                    </PathGeometry.Figures>
                                                </PathGeometry>
                                            </Path.Data>
                                        </Path>
                                    </Grid>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <TextBlock Text="{Binding Header}"/>
                    </DockPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <e:Interaction.Triggers>
                <e:EventTrigger EventName="MouseUp">
                    <inf:MapMouseEventToCommand Command="{Binding SetActiveCommand}" />
                </e:EventTrigger>
            </e:Interaction.Triggers>
        </TabControl>

        <vc:ProgressNotificationBar Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" />

        <TextBlock Text="" Padding="2" Grid.Row="3" />
    </Grid>
</UserControl>